<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
    <!--第三方lib-->
  <script src="./lib/cesiumjs/Cesium/Cesium.js"></script>
    <link href="./lib/cesiumjs/Cesium/Widgets/Widgets.css" rel="stylesheet">

<!--      <script src="https://cesium.com/downloads/cesiumjs/releases/1.65/Build/Cesium/Cesium.js"></script>-->
<!--  <link href="https://cesium.com/downloads/cesiumjs/releases/1.65/Build/Cesium/Widgets/widgets.css" rel="stylesheet">-->

  <style>
    html,
    body,
    #cesiumContainer {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #000000;
    }
</style>
</head>
<body>
  <div id="cesiumContainer" style="width: 100%"></div>
  <script>

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZWE2NTRhOC1kYTZlLTQ0YzMtOWJiNi02ZTU2ZjlmOTg1MGMiLCJpZCI6MTQyODgsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NjUxNzU4MjJ9.-MyI5VpHz6X6JXRNFDQ2OPfVQHg90qO-lrBS8PrUY5w';
    var viewer = new Cesium.Viewer('cesiumContainer', {
      terrainProvider: Cesium.createWorldTerrain(),
      animation:false,       //是否显示动画控件
      homeButton:false,       //是否显示home键
      geocoder:false,         //是否显示地名查找控件        如果设置为true，则无法查询
      baseLayerPicker:false, //是否显示图层选择控件
      timeline:false,        //是否显示时间线控件
      fullscreenButton:true, //是否全屏显示
      scene3DOnly:true,     //如果设置为true，则所有几何图形以3D模式绘制以节约GPU资源
      infoBox:true,         //是否显示点击要素之后显示的信息
      sceneModePicker:true,  //是否显示投影方式控件  三维/二维
      navigationInstructionsInitiallyVisible:false,
      navigationHelpButton:false,     //是否显示帮助信息控件
      selectionIndicator:false//是否显示指示器组件

    });
    viewer._cesiumWidget._creditContainer.style.display="none";

    let url1 = window.location.href.split('?url=')[1];
    let dataUrl = url1.split('&type=')[0]; //通过截断的方式获得画面URL字符串中elementUrl
    // var dataUrl =  'http://data.marsgis.cn/3dtiles/qx-shuiwu/tileset.json';

    var dataType =  window.location.href.split("&type=")[1];//获得画面URL字符串中serviceType
    var serviceType= JSON.parse(dataType);
    debugger
    var entity = load3Dtiles(dataUrl);
    var vector = loadGeoJson(dataUrl);
    switch(serviceType) {

      case 1:
        window.viewer.scene.primitives.remove(entity);
        break;
      case 2:
        window.viewer.scene.primitives.remove(entity);
        break;
      case 3:
        window.viewer.scene.primitives.remove(entity);
        break;
      case 4:
        viewer.entities.remove(vector);
    }


    function load3Dtiles(dataUrl) {
      //加载三维模型，此方法可设置相机初始视角
      var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: dataUrl,
        maximumScreenSpaceError: 2,
        dynamicScreenSpaceError : true,
      }));
      tileset.modelMatrix = Cesium.Matrix4.fromArray([
        1.0, 0.0, 0.0, 0.0,
        0.0, 1.0, 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0
      ]);
      oneLayer = viewer.scene.primitives.add(tileset);
      tileset.readyPromise.then(function (tileset) {
        viewer.scene.primitives.add(tileset);
        viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.5, tileset.boundingSphere.radius * 0.5));
      }).otherwise(function (error) {
        console.log(error);
      });
      return tileset
    };

    function loadGeoJson(dataUrl) {

      var data = window.viewer.dataSources.add(Cesium.GeoJsonDataSource.load(dataUrl, {
        // stroke: Cesium.Color.HOTPINK,//颜色样式渲染
        // fill: Cesium.Color.PINK,
        // strokeWidth: 3,
        //markerSymbol: './gis/data/geojson/render.png'
      }));
      window.viewer.zoomTo(data);
    }




  </script>
</body>
</html>
